package com.fishery.authority.service.impl;

import com.fishery.authority.entity.Role;
import com.fishery.authority.mapper.RoleMapper;
import com.fishery.authority.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fishery.entity.GlobalException;
import com.fishery.entity.Result;
import com.fishery.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 711
 * @since 2021-01-13
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public void deleteALLBaseFunctionById(String baseId, String baseIdentity) {

    }

    /**
     * 根据ID查询实体
     * @param id
     * @return
     */
    @Override
    public Role findById(String id) {
        Role role = baseMapper.selectById(id);
        // 若为空就抛出错误
        if(role.equals(null)){
            throw new GlobalException(new Result(false, StatusCode.ERROR, "角色不存在", null));
        }
        return role;
    }

    /**
     * 查询该管理员尚未被赋予的角色
     */
    @Override
    public List<Role> findOthersByUserId(String userId) {
        return roleMapper.findOthersByUserId(userId);
    }

    /**
     * 查询该管理员尚已赋予的角色
     */
    @Override
    public List<Role> findRoleByUserId(String userId) {
        return roleMapper.findByUserId(userId);
    }
}
